<?php

namespace App\Console\Commands;

use App\Library\Logic\MigrationsLogic;
use Illuminate\Console\Command;
use Illuminate\Support\Facades\Artisan;

class AdminAuthCommand extends Command
{
    /**
     * The name and signature of the console command.
     *
     * @var string
     */
    protected $signature = 'command:adminAuth';

    /**
     * The console command description.
     *
     * @var string
     */
    protected $description = 'Command description';

    /**
     * Execute the console command.
     */
    public function handle(): void
    {
        Artisan::call('command:migrations');
        MigrationsLogic::deleteByWhere([
            'whereIn' => ['migration', $this->hTable()],
        ]);
        Artisan::call('migrate --force');
        Artisan::call('command:migrations');
    }

    /**
     * hTable
     */
    private function hTable(): array
    {
        foreach ($this->tableArr() as $v) $arr[] = '2024_01_01_000000_create_' . $v . '_table';
        return $arr ?? [];
    }

    /**
     * tableArr
     */
    private function tableArr(): array
    {
        return [
            'admin_menu',
            'admin_permissions',
            'admin_role_menu',
            'admin_role_permissions',
            'admin_role_users',
            'admin_roles',
            'admin_user_permissions',
            'admin_users',
        ];
    }
}
